import { DescItem } from '/@/components/Description';
import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { FullSrcPic } from '/@/components/FullSrcPic/index';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';

export function getBasicColumns(): BasicColumn[] {
  return [
    {
      title: '地址',
      dataIndex: 'address',
    },
    {
      title: '房屋编号',
      dataIndex: 'yhfwbh',
    },
    {
      title: '区县',
      dataIndex: 'xzqdmAlias',
    },
    {
      title: '街道',
      dataIndex: 'townAlias',
    },
    {
      title: '初判结果',
      dataIndex: 'aqyhcpAlias',
    },
    {
      title: '区县审核结果',
      dataIndex: 'result',
      width: 150,
      slots: { customRender: 'chkresult' },
    },
  ];
}


export function getCityBasicColumns(): BasicColumn[] {
  return [
    {
      title: '地址',
      dataIndex: 'address',
    },
    {
      title: '房屋编号',
      dataIndex: 'yhfwbh',
    },
    {
      title: '区县',
      dataIndex: 'xzqdmAlias',
    },
    {
      title: '街道',
      dataIndex: 'townAlias',
    },
    {
      title: '初判结果',
      dataIndex: 'aqyhcpAlias',
    },
    {
      title: '市级审核结果',
      dataIndex: 'cityResult',
      width: 150,
      slots: { customRender: 'chkresult' },
    },
    // {
    //   title: '区县审核结果',
    //   dataIndex: 'result',
    //   width: 150,
    //   slots: { customRender: 'chkresult' },
    // },
  ];
}

export function getBasicShortColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      width: 150,
      dataIndex: 'id',
      sorter: true,
      sortOrder: 'ascend',
    },
  ];
}

export function getMultipleHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 200,
    },
  ];
}

export function getCustomHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 200,
    },
  ];
}
const renderContent = ({ text, index }: { text: any; index: number }) => {
  const obj: any = {
    children: text,
    attrs: {},
  };
  if (index === 9) {
    obj.attrs.colSpan = 0;
  }
  return obj;
};
export function getMergeHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 300,
      customRender: renderContent,
    },
  ];
}
export const getAdvanceSchema = (itemNumber = 6): FormSchema[] => {
  const arr: any = [];
  for (let index = 0; index < itemNumber; index++) {
    arr.push({
      field: `field${index}`,
      label: `字段${index}`,
      component: 'Input',
      colProps: {
        xl: 12,
        xxl: 8,
      },
    });
  }
  return arr;
};
export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      ...getAdvanceSchema(5),
      {
        field: `field11`,
        label: `Slot示例`,
        component: 'Select',
        slot: 'custom',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}
export function getBasicData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
      });
    }
    return arr;
  })();
  return data;
}

export function getTreeTableData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
        children: [
          {
            id: `l2-${index}`,
            name: 'John Brown',
            age: `1${index}`,
            no: `${index + 10}`,
            address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
            beginTime: new Date().toLocaleString(),
            endTime: new Date().toLocaleString(),
          },
        ],
      });
    }
    return arr;
  })();

  return data;
}

export function getLastCheckDescSchema(): DescItem[] {
  return [
    {
      label: '检查结果',
      field: 'result',
      render: (curVal, data) => {
        if (1 == curVal) {
          return h(Tag, { color: 'green' }, () => '通过');
        } else if (0 == curVal) {
          return h(Tag, { color: 'red' }, () => '不通过');
        } else {
          return h(Tag, {}, () => '未核查');
        }
      },
    },
    {
      label: '检查人',
      field: 'modifiedByName',
    },
    {
      label: '检查时间',
      field: 'modifiedOn',
    },
    {
      label: '检查意见',
      field: 'note',
    },
    {
      label: '现场照片',
      field: 'photoIds',
      render: (curVal, data) => {
        return h(FullSrcPic, {
          boolVal: false,
          picList: curVal,
        });
      },
    },
  ];
}

export const searchByCityFormSchema: FormSchema[] = [
  {
    field: 'addr',
    label: '地址',
    component: 'Input',
    labelWidth: '6em',
    colProps: { span: 6 },
  },
  {
    field: 'fwbh',
    label: '房屋编号',
    component: 'Input',
    labelWidth: '6em',
    colProps: { span: 6 },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    labelWidth: '6em',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: '全部', value: 0 },
        { label: '正确', value: 1 },
        { label: '不正确', value: 2 },
        { label: '未核查', value: 3 },
      ],
    },
  },
];
